using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region VehicleType

	/// <summary>
	/// VehicleType object for NHibernate mapped table 'VehicleType'.
	/// </summary>
	[Serializable]
	public class VehicleType : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _vehicleTypeName;
		protected decimal _price;
		protected string _vehicleSource;
		protected IList _vehicleBookings;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public VehicleType() { }

		public VehicleType( string vehicleTypeName, decimal price, string vehicleSource )
		{
			this._vehicleTypeName = vehicleTypeName;
			this._price = price;
			this._vehicleSource = vehicleSource;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string VehicleTypeName
		{
			get { return _vehicleTypeName; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for VehicleTypeName", value, value.ToString());
				_vehicleTypeName = value;
			}
		}

		public decimal Price
		{
			get { return _price; }
			set { _price = value; }
		}

		public string VehicleSource
		{
			get { return _vehicleSource; }
			set
			{
				if ( value != null && value.Length > 10)
					throw new ArgumentOutOfRangeException("Invalid value for VehicleSource", value, value.ToString());
				_vehicleSource = value;
			}
		}

		public IList VehicleBookings
		{
			get
			{
				if (_vehicleBookings==null)
				{
					_vehicleBookings = new ArrayList();
				}
				return _vehicleBookings;
			}
			set { _vehicleBookings = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is VehicleType))
				throw new InvalidCastException("This object is not of type VehicleType");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((VehicleType)obj).Id);
					break;
				case "VehicleTypeName":
						relativeValue = ( this.VehicleTypeName != null ) ? this.VehicleTypeName.CompareTo(((VehicleType)obj).VehicleTypeName) : -1;
					break;
				case "Price":
					relativeValue = this.Price.CompareTo(((VehicleType)obj).Price);
					break;
				case "VehicleSource":
						relativeValue = ( this.VehicleSource != null ) ? this.VehicleSource.CompareTo(((VehicleType)obj).VehicleSource) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (VehicleType.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
